<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>登录</title>
  <link rel="stylesheet" type="text/css" href="#(base)/fslayui/plugins/layui/css/layui.css" media="all"/>
  <link rel="stylesheet" href="#(base)/fslayui/css/login.css">
	<script type="text/javascript" src="#(base)/fslayui/plugins/jquery/jquery.min.js"></script>
  <script type="text/javascript" src="#(base)/fslayui/plugins/layui/layui.js"></script>
  <script type="text/javascript" src="#(base)/js/common/Mtils.js"></script>
</head>
<body>

<div class="login-back"></div>
	<div class="layui-container">
		<div class="logo"><img src="#(base)/fslayui/images/logo.png" width="50" height="50"></div>
		<div class="logo-title">学员军事训练管理系统</div>
		<div class="logo-txt">Student Military Training Management System</div>
		<div class="layui-row login-box">
		    <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
		      	<div class="login-img"><img src="#(base)/fslayui/images/login-left.png"></div>
		    </div>
			<form method="post" class="layui-form">
		    <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
		      	<div class="login-tt">账户登录</div>
		      	<div class="login-form">
		      		<input id="username" type="text" lay-filter="username" name="username" placeholder="请输入用户名" lay-verify="required" class="layui-input login01">
		      		<input id="password" type="password" lay-filter="password" name="password" placeholder="请输入密码" lay-verify="required" class="layui-input login02">

		      		<button lay-submit lay-filter="login" class="layui-btn login-btn">登录</button>
		      	</div>
		    </div>
			</form>
		</div>
	</div>
<script>
	layui.use(['form','layer'],function(){
		var form = layui.form;
		var layer = layui.layer;
		form.on('submit(login)', function(data){
			var loginload = layer.load();
			var formdata = data.field;
			formdata['password'] = Mtils.security.hex_md5(formdata['password']);
			$.ajax({
				type:"POST",
				url:"/login",
				dataType:"json",
				data:formdata,
				success:function(data){
					layer.close(loginload);
					console.log(data)
					if(data.state == 'ok'){
						layer.msg(data.msg, {icon: 1,anim: 0},function(){
							window.location.href="#(base)/";
						});
					}else{
						layer.msg(data.msg, {icon: 2,anim: 6},function () {
							$("#codeimg").attr('src', "#(base)/login/randomcode?t=" + Math.random());
						});
					}
				},
				error:function(jqXHR){
					layer.close(loginload);
					layer.msg("发生错误："+jqXHR.status, {icon: 2,anim: 6});
					console.log("发生错误："+jqXHR.status);
				}
			});
			return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});
	})

	function reCode(){
		$("#codeimg").attr('src', "#(base)/login/randomcode?t=" + Math.random());
	}
</script>
</body>
</html>
